<?php

namespace common\models;

use common\components\big_data\BaiRong;
use common\components\tools\Tools;

/**
 * @property BaiRongValidateForCreditOrder[] $baiRongValidateForCreditOrders
 */
class BaiRongValidateLog extends \common\models\base\BaiRongValidateLog
{
    const STRATEGY_TYPE_DETAIL_LIST = 'detail_list'; // 百融大数据  STR0023330 (就是目前在用的STR0000798）只是少了复议
    const STRATEGY_TYPE_PERSON_RECOGNITION = 'person_recognition';
    const STRATEGY_TYPE_MOBILE_INLINE_STATUS = 'mobile_inline_status'; // 手机在网状态（规则）反基础数据模块
    const STRATEGY_TYPE_MOBILE_INLINE_TIME = 'mobile_inline_time'; // 手机在网时长（规则）反基础数据模块
    const STRATEGY_TYPE_DTV0000002 = 'DTV0000002';
    const STRATEGY_TYPE_MCP0022667 = 'MCP0022667'; // 易商验证流程001
    const STRATEGY_TYPE_MCP0022668 = 'MCP0022668'; // 易商验证流程002

    const STRATEGY_TYPE_STR0023309 = 'STR0023309'; // 工行信用评分
    const STRATEGY_TYPE_STR0022664 = 'STR0022664'; // 逻辑回归 易商贷前整体策略001
    const STRATEGY_TYPE_STR0022666 = 'STR0022666'; // xgb
    const STRATEGY_TYPE_STR0022665 = 'STR0022665'; // 偿还能力 贷前整体策略002
    const STRATEGY_TYPE_MCP0023329 = 'MCP0023329'; // 自然人识别
    const STRATEGY_TYPE_MCP0023326 = 'MCP0023326'; // 手机三要素
    const STRATEGY_TYPE_MCP0023327 = 'MCP0023327'; // 手机在网时长 手机在网状态
    const STRATEGY_TYPE_MCP0023328 = 'MCP0023328'; // 银行流水验证
    const STRATEGY_TYPE_STR0023330 = 'STR0023330'; // 只是少了复议
    const STRATEGY_TYPE_MCP0023388 = 'MCP0023388'; // 二要素认证


    const IMPORT_TYPE_DEFAULT = 1;
    const IMPORT_TYPE_EXCEL = 2;

    /**
     * @throws
     */
    public function showOtherData()
    {
        switch ($this->strategy_type){
            case BaiRongValidateLog::STRATEGY_TYPE_DETAIL_LIST:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_PERSON_RECOGNITION:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MOBILE_INLINE_STATUS:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MOBILE_INLINE_TIME:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_DTV0000002:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0022667:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0022668:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_STR0023309:
                if (isset($this->resp_data_for_api_send['swift_number'])) {
                    if (isset($this->resp_data_for_api_send['rs_final_decision'])){
                        $this->other_data .= $this->resp_data_for_api_send['rs_final_decision'];
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_STR0022664:
                if (isset($this->resp_data_for_api_send['swift_number'])) {
                    // 反欺诈规则集结果 反欺诈评分结果  信用评分
                    if (isset($this->resp_data_for_api_send['rs_Rule_decision'])){
                        $this->other_data .= $this->resp_data_for_api_send['rs_Rule_decision'];
                    }
                    $this->other_data.=";";
                    if (isset($this->resp_data_for_api_send['rs_ScoreAf_decision'])){
                        $this->other_data .= $this->resp_data_for_api_send['rs_ScoreAf_decision'];
                    }
                    $this->other_data.=";";
                    if (isset($this->resp_data_for_api_send['rs_Score_scorecust'])){
                        $this->other_data .= $this->resp_data_for_api_send['rs_Score_scorecust'];
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_STR0022666:
                if (isset($this->resp_data_for_api_send['swift_number'])) {
                    if (isset($this->resp_data_for_api_send['rs_final_decision'])){
                        $this->other_data .= $this->resp_data_for_api_send['rs_final_decision'];
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_STR0022665:
                if (isset($this->resp_data_for_api_send['swift_number'])){
                    if (isset($this->resp_data_for_api_send['scorecust2'])){
                        $this->other_data .= $this->resp_data_for_api_send['scorecust2'];
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0023329:
                if (isset($this->resp_data_for_api_send['swift_number'])){
                    if (isset($this->resp_data_for_api_send['Flag']['badinfo']) && !$this->resp_data_for_api_send['Flag']['badinfo']){
                        $this->other_data .= "正常";
                    }
                    if (isset($this->resp_data_for_api_send['BadInfo']['ztCheckresult'])&&$this->resp_data_for_api_send['BadInfo']['ztCheckresult']){
                        $this->other_data .= "zt ";
                    }
                    if (isset($this->resp_data_for_api_send['BadInfo']['sdCheckresult'])&&$this->resp_data_for_api_send['BadInfo']['sdCheckresult']){
                        $this->other_data .= "sd ";
                    }
                    if (isset($this->resp_data_for_api_send['BadInfo']['xdCheckresult'])&&$this->resp_data_for_api_send['BadInfo']['xdCheckresult']){
                        $this->other_data .= "xd ";
                    }
                    if (isset($this->resp_data_for_api_send['BadInfo']['item'])){
                        $item = $this->resp_data_for_api_send['BadInfo']['item'];
                        $type_dist = BaiRong::$case_type_dist;
                        if (isset($item['caseTypeCode'])){
                            if (isset($type_dist[$item['caseTypeCode']])){
                                $x = $type_dist[$item['caseTypeCode']];
                            }else{
                                $x = "其他";
                            }
                            $this->other_data .= "最近时间{$item['caseTime']}". $x."({$item['caseTypeCode']})".";";
                        }
                    }
                    if (isset($this->resp_data_for_api_send['InfoVerification']['hit_rules'])){
                        foreach ($this->resp_data_for_api_send['InfoVerification']['hit_rules'] as $k => $v){
                            foreach ($v as $k1 => $v1){
                                $this->other_data .= "{$v1['name_rule']} ";
                            }
                        }
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0023326:
                if (isset($this->resp_data_for_api_send['swift_number'])) {
                    if (isset($this->resp_data_for_api_send['InfoVerification']['final_decision'])){
                        $this->other_data .= $this->resp_data_for_api_send['InfoVerification']['final_decision'];
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0023327:
                if (isset($this->resp_data_for_api_send['swift_number'])) {
                    $x = [];
                    if (isset($this->resp_data_for_api_send['TelPeriod']['data']['value'])){
                        $x[] = $this->resp_data_for_api_send['TelPeriod']['data']['value'];
                    }
                    if (isset($this->resp_data_for_api_send['TelStatus']['data']['value'])){
                        $x[] = $this->resp_data_for_api_send['TelStatus']['data']['value'];
                    }
                    $this->other_data .= Tools::arr2str($x, ";");
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0023328:
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_STR0023330:
                if (isset($this->resp_data_for_api_send['swift_number'])) {
                    if (isset($this->resp_data_for_api_send['rs_final_decision'])){
                        $this->other_data .= $this->resp_data_for_api_send['rs_final_decision'];
                    }
                }
                break;
            case BaiRongValidateLog::STRATEGY_TYPE_MCP0023388:
                if (isset($this->resp_data_for_api_send['swift_number'])){
                    if (isset($this->resp_data_for_api_send['InfoVerification']['hit_rules']['rule_c_idtwo_z'])){
                        $x = $this->resp_data_for_api_send['InfoVerification']['hit_rules']['rule_c_idtwo_z'];
                        $y = current($x);
                        $this->other_data = $y['name_rule'];
                    }
                }
                break;
            default:
                throw new ApiException(201902251608, "没有找到策略");
                break;
        }
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getBaiRongValidateForCreditOrders()
    {
        return $this->hasMany(BaiRongValidateForCreditOrder::className(), ['bai_rong_validate_log_id' => 'id']);
    }
}
